package de.haw.adt.implementation;

import static de.haw.adt.implementation.Values.FEET_IN_METERS;
import static de.haw.adt.implementation.Values.KILO;
import de.haw.adt.interfaces.IArea;

class Area extends AbstractPhysicalScalar implements IArea {
	
	private final double squaremeters;
	
	private Area(double squaremeters) {
		this.squaremeters = squaremeters;
	}

	@Override
	double getValue() {
		return squaremeters;
	}

	public int compareTo(IArea o) {
		return Double.compare(squaremeters, o.sqm());
	}

	@Override
	public boolean equals(Object o) {
		if (o == this)
			return true;
		if (!(o instanceof IArea))
			return false;
		return this.compareTo((IArea) o) == 0;
	}
	
	public double sqft() {
		return squaremeters * FEET_IN_METERS;
	}

	public double sqm() {
		return squaremeters;
	}

	public double sqkm() {
		return squaremeters / KILO;
	}

	public IArea add(IArea area) {
		return valueOf(squaremeters + area.sqm());
	}

	public IArea sub(IArea area) {
		return valueOf(squaremeters - area.sqm());
	}
	public IArea mul(double factor) {
		return valueOf(squaremeters * factor);
	}

	public IArea div(double factor) {
		return valueOf(squaremeters / factor);
	}
	
	public static Area valueOf(double squaremeters) {
		return new Area(squaremeters);
	}
}
